<script lang="ts" setup>
import { reactive, ref } from 'vue'
import store from '../../store'
import axios from "axios"
import type { FormInstance, FormRules, UploadProps, UploadUserFile } from 'element-plus'
var goBack = function () {
  window.location.replace("../Home/Home.html");
};
// do not use same name with ref
store.getStu()
let Type = ''
const ruleFormRef = ref<FormInstance>()

const form_1 = reactive({
  bulk: '',
  type: '',
})
const value = ref('');
const input = ref('');
const size = ref('large')
const rules = reactive<FormRules>({
  xiugai: [
    { required: true, message: '请输入活动标题', trigger: 'blur' }
  ],
  type: [
    { required: true, message: '请选择修改类型', trigger: 'blur' }
  ]
})
//  组织信息修改，为了方便后端，组织信息修改要联系开发者修改，后期时间充裕完善后端后，直接取消注释前端即可用
// const submitForm = async (formEl: FormInstance | undefined) => {
//   if (!formEl) return
//   await formEl.validate((valid, fields) => {
//     if (valid) {
//       var first=form_1.type
//       var last=form_1.bulk
//       console.log(form_1.type)
//   var proxy={
//       [first]:last,
//       orgName:store.state.Stu[0].orgName
// }
//     console.log(proxy)
//     axios({
//       url:'http://192.168.2.108:3000/changeMsg',
//       method: 'post',
//       data:proxy
//   })
//   console.log('success') 
//   alert('成功修改')
//   setTimeout(function(){
//     goBack()
//   },500)}
//      else {
//       console.log('error submit!')
//       alert('失败请重试')
//     }
//   })
// }

const submitForm_stu = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      var first = form_1.type
      var last = form_1.bulk
      console.log(form_1.type)
      //   var proxy={
      //       [first]:last,
      //       schNo:store.state.Stu[0].schNo
      // }
      var regContent_form = new FormData()
      // regContent_form.append("sch_No", store.state.Stu[0].schNo)
      regContent_form.append("name", store.state.Stu[0].name)
      regContent_form.append("nick", store.state.Stu[0].nick)
      regContent_form.append("password", store.state.Stu[0].pwd)
      regContent_form.append("gender", store.state.Stu[0].gender)
      regContent_form.append("insit", store.state.Stu[0].insit)
      regContent_form.append("profile", store.state.Stu[0].profile)
      regContent_form.append("selfIntro", store.state.Stu[0].selfIntro)
      regContent_form.append("wechatNo", store.state.Stu[0].wechatNo)
      regContent_form.append("qqNo", store.state.Stu[0].qqNo)
      regContent_form.delete(first)
      regContent_form.append(first, last)
      // console.log(proxy)
      if (store.state.Stu[0].type == "军人") {
        axios({
          url: 'http://8.130.46.21:8000/soldier/msg/change?schNo='+store.state.Stu[0].schNo,
          // url: 'http://8.130.46.21:8000/soldier/msg/change?schNo=2227777777',
          method: 'post',
          data: regContent_form
        })
        console.log('success')
        alert('成功修改，重新启动应用生效')
        setTimeout(function(){
          goBack()
        },500)
      }

      else if (store.state.Stu[0].type == "学生") {
        axios({
          url: 'http://8.130.46.21:8000/stu/msg/change?schNo='+store.state.Stu[0].schNo,          
          // url: 'http://8.130.46.21:8000/stu/msg/change?schNo=2227777777',
          method: 'post',
          data: regContent_form
        })
        console.log('success')
        alert('成功修改，重新启动应用生效')
        setTimeout(function(){
          goBack()
        },500)
      }
    }
    else {
      console.log('error submit!')
      alert('失败请重试')
    }
  })
}
</script>



<template>
  <div class>
    <!-- <div class="main" v-if="store.state.Stu[0].type == '组织'">
                <div class="grxx">
                  <div class="back" @click="goBack()">
                    <svg class="icon" aria-hidden="true">
                      <use xlink:href="#icon-left" />
                    </svg>
                  </div>修改信息
                </div>
                <div class="gap"></div>
                <el-form
                  :model="form_1"
                  label-width="80px"
                  :label-position="labelPosition"
                  :size="size"
                  :rules="rules"
                  ref="ruleFormRef"
                >
                  <el-form-item label="修改项" prop="type">
                    <el-select v-model="form_1.type" placeholder="请选择修改项">
                      <el-option label="组织名称(联系开发者修改)" value="orgName" disabled />
                      <el-option label="组织介绍" value="orgIntro" />
                      <el-option label="密码" value="pswd" />
                    </el-select>
                  </el-form-item>
                  <div class="gap"></div>
                  <el-form-item label="修改内容">
                    <el-input v-model="form_1.bulk" />
                  </el-form-item>
                  <div class="gap"></div>
                  <el-form-item>
                    <el-button type="primary" @click="submitForm(ruleFormRef)">Primary</el-button>
                  </el-form-item>
                </el-form>
              </div> -->
    <!-- <div
                class="main"
                v-if="(store.state.Stu[0].type == '军人')||(store.state.Stu[0].type == '学生')"
              > -->
    <div class="grxx">
      <div class="back" @click="goBack()">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-left" />
        </svg>
      </div>修改信息
    </div>
    <div class="gap"></div>
    <el-form :model="form_1" label-width="80px" :size="size" :rules="rules" ref="ruleFormRef">
      <el-form-item label="修改项" prop="type">
        <el-select v-model="form_1.type" placeholder="请选择修改项">
          <el-option label="学号" value="schNo" disabled />
          <el-option label="昵称" value="nick" />
          <el-option label="性别" value="gender" />
          <el-option label="书院" value="insit" />
          <el-option label="手机号" value="phoneNo" disabled />
          <el-option label="QQ" value="qqNo" />
          <el-option label="微信号" value="wechatNo" />
          <el-option label="密码" value="pswd" />
        </el-select>
      </el-form-item>
      <div class="gap"></div>
      <el-form-item label="修改内容">
        <el-input v-model="form_1.bulk" />
      </el-form-item>
      <div class="gap"></div>
      <el-form-item>
        <el-button type="primary" @click="submitForm_stu(ruleFormRef)">提交</el-button>
      </el-form-item>
    </el-form>

  </div>
  <!-- </div> -->
</template>



<style scoped>
.upload-demo {
  width: 100%;
}

.back {
  position: absolute;
  color: white;
  line-height: 30px;
  padding-left: 10px;
  /* background-color: #fff; */
  padding-right: 10px;
}

.grxx {
  /* display: block; */
  /* background-color: gray; */
  width: 100%;
  /* position: absolute; */
  font-size: 20px;
  text-align: center;
  padding-top: 10px;
  padding-bottom: 10px;
  color: rgb(79, 79, 79);
}

.gap {
  height: 20px;
}
</style>